//
//  NotPayListViewController.m
//  PropertyManager
//
//  Created by 黎世炜 on 2018/11/6.
//  Copyright © 2018年 Tng. All rights reserved.
//

#import "NotPayListViewController.h"
#import "SWNotPayTableViewCell.h"
#import "UIViewController+SWNavigationBarSetting.h"
#import "SWNotPayDetailsViewController.h"
@interface NotPayListViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (weak, nonatomic) IBOutlet UILabel *sumPayNumLabel;
@property (weak, nonatomic) IBOutlet UILabel *listCountLabel;
@property (strong, nonatomic) NSMutableArray * dataArr;
@property (strong, nonatomic) NotPayModel * moneyModel;
@end

@implementation NotPayListViewController
    
-(instancetype)init{
    if(self = [super init]){
        self = [[UIStoryboard storyboardWithName:@"NotPayListStoryboard" bundle:nil] instantiateInitialViewController];
    }
    return self;
}
    
- (void)viewDidLoad {
    [super viewDidLoad];
    [self RequestData];
    [self.tableView registerNib:[UINib nibWithNibName:@"SWNotPayTableViewCell" bundle:nil] forCellReuseIdentifier:@"SWNotPayTableViewCell"];
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    [self setRightItemWithIcon:nil title:@"历史账单" selector:@selector(clickToHistoryList)];
    // Do any additional setup after loading the view.
}
    
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    SWNotPayTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"SWNotPayTableViewCell" forIndexPath:indexPath];
    self.moneyModel = self.dataArr[indexPath.row];
    cell.model = self.moneyModel;
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
     self.moneyModel = self.dataArr[indexPath.row];
    SWNotPayDetailsViewController * vc = [[SWNotPayDetailsViewController alloc] init];
    vc.model = self.moneyModel;
    [self.navigationController pushViewController:vc animated:YES];
}

-(void)clickToHistoryList{
    PayMoneyRecodeViewController * ctr = [[PayMoneyRecodeViewController alloc] init];
    [self.navigationController pushViewController:ctr animated:YES];
}

-(void)RequestData{
    WeakSelf;
    //    NSString * urlStr = [NSString stringWithFormat:@"rest/gbBqsftzdController/getList?pageno=1&pagesize=10&pkCustomerid=%@",SFMgbuserid];
    NSString * urlStr = [NSString stringWithFormat:@"/rest/gbBqsftzdController/getPay?pkCustomerid=%@",SFMgbuserid];
    [[HTTPClient shareClient] requestWithPath:urlStr AndReturnBlock:^(NSDictionary *dic) {
        
        NSArray * dataArr = dic[@"data"];
        for (NSDictionary * dics in dataArr) {
            NotPayModel * model = [NotPayModel yy_modelWithDictionary:dics];
            [weakSelf.dataArr addObject:model];
        }
        dispatch_async(dispatch_get_main_queue(), ^{
            [weakSelf.tableView reloadData];
            weakSelf.listCountLabel.text = [NSString stringWithFormat:@"未缴费账单共%zd笔",weakSelf.dataArr.count];
        });
    } AndFailMessage:^(NSString *message, NSString *errorCode) {
        [SVProgressHUD ShowErrorMessage:message];
    }];
}
    
-(NSMutableArray *)dataArr{
    if (!_dataArr) {
        _dataArr = [NSMutableArray array];
    }
    return _dataArr;
}
    
@end
